package com.tz.liveplayermodule.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.baijiayun.glide.Glide;
import com.baijiayun.glide.load.resource.bitmap.RoundedCorners;
import com.baijiayun.glide.request.RequestOptions;
import com.tz.liveplayermodule.R;

import java.util.List;

/**
 * Created by tz on 2017/4/25.
 */

public class ListView3Adapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<String> mIntegralList;
    private Context mContext;
    private int mImgWidth, mImgHeight;

    public ListView3Adapter(Context context, List<String> integralList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        mIntegralList = integralList;
    }

    @Override
    public int getCount() {
        return mIntegralList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.item_listview3, null);
            holder = new ViewHolder();
            holder.ppt_img = (ImageView) view.findViewById(R.id.ppt_img);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        //设置图片圆角角度
        RoundedCorners roundedCorners = new RoundedCorners(6);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);

        Glide.with(mContext).load(mIntegralList.get(i)).apply(options).into(holder.ppt_img);
        return view;
    }

    private class ViewHolder {
        ImageView ppt_img;
    }

}
